home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
pas_0493.zip
/
PASCAL-3.FAQ
< prev
next >
Wrap
Text File
|
1993-04-13
|
4KB
|
125 lines
─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
Msg : 393 of 439
From : Max Maischein 2:249/6.17 09 Apr 93 19:19
To : All
Subj : FAQ ]I[
────────────────────────────────────────────────────────────────────────────────
PASCAL.FAQ Frequently asked questions about Pascal
The aim of this document is to give answers to frequently asked
questions in the pascal echo. Thumb rules before asking for help are to
look in the manuals and in the online help first. Many problems can be
solved by just looking into either / both of them. Here are some
topics, that come very often in the Pascal Echo.
Part ]I[
#6: Controling user input and the cursor
---------------------------------------------------------------------
#6: Controling user input and the cursor
Q1: How to I read a number from the keyboard ?
Q2: How can I use the cursor keys with ReadLn ?
A1: The simplest way would be just to code :
ReadLn( Number );
Here, you would have to turn off IO-checking, because if the user
enters a string ( "How old are you ?" - "eighteen" ), and do the
checking with IOResult.
A2: Another way would be to read a string and then do the parsing with
the procedure Val(), any wrong input would result in the error variable
being non-zero.
A3: If you need support for cursor down, ESC and other keys, you will
need to do it all by yourself. The procedure below might not be the
fastest, but you can specify all keys that are allowed to be typed, e.g.
for file names, "?" and "*" would not be allowed :
Uses CRT;
Type TCharSet = Set of Char;
Const Alpha : TCharSet = ['A'..'Z','a'..'z'];
Numbers : TCharSet = ['0'..'9'];
HexNumbers : TCharSet = ['0'..'9', 'A'..'F', 'a'..'f'];
Function StringOf( Ch : Char; Len : Byte ) : String;
Var Result : String;
Begin
FillChar( Result[ 1 ], Len, Ch );
Result[ 0 ] := Char( Len );
StringOf := Result;
End;
Function GetInput( X,Y,MaxLen : Byte; Const Default : String; Allowed :
TCharSet ) : String;
Var Result : String;
CursorPos : Byte;
Done : Boolean;
Ch : Char;
Begin
Result := Default;
Done := False;
CursorPos := Length( Result )+1;
Repeat
GotoXY( X,Y );
Write( StringOf( #176, MaxLen ));
GotoXY( X,Y );
Write( Result );
GotoXY( X+CursorPos-1, Y );
Ch := ReadKey;
Case Ch of
#0 : Case ReadKey of
'K' : If CursorPos > 1
then Dec( CursorPos );
'M' : If CursorPos < Succ( Length( Result ))
then Inc( CursorPos );
End;
#127,#8 : If CursorPos > 1
then
Begin
Dec( CursorPos );
Delete( Result, CursorPos,1 );
End;
#13 : Done := True;
#27 : Begin
Result := '';
Done := True;
End;
else
If ( Ch in Allowed ) and ( Length( Result ) < MaxLen )
then
Begin
Insert( Ch, Result, Cursorpos );
Inc( CursorPos );
End;
End;
Until Done;
GetInput := Result;
End;
Begin
WriteLn( GetInput( 10,10,10,'Test',Alpha ));
WriteLn( GetInput( 10,10,20,'1234',Numbers));
WriteLn( GetInput( 10,10,20,'1234',HexNumbers ));
End.
A4: Switch to Turbo Vision. This the most complicated way of getting a
full size input line, but you get full mouse support and windows with
it. If you don't need either, you can as well use the aboe routine, but
if you plan on going mousewards, you're better off with TV or other
'Application Frameworks'. The words to look for in the TV-Manuals are
Insert, InsertWindow, GetData / SetData, TInputLine and TWindow.
---------------------------------------------------------------------
-max
This file is copyrighted by Max Maischein, 2:249/6.17.
No part thereof may be printed without my written permission.
---
* Origin: Arrays of Pointers to Arrays of Pointers to ... (2:249/6.17)